package com.zhou.common.mybatis.template.shiro.zhou.aop;

/**
 * pageHelper切面，在切面中做分页
 */

/*
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

import com.github.pagehelper.PageHelper;
import com.iwhalecloud.mgtcenter.entity.base.PageQuery;

*/
/**
 * Created with IDEA
 * 分页处理AOP 切入分页注解
 * 1.只处理继承了PageQuery类的分页
 * 2.分页是对第一条！！！查询SQL分页
 *
 * @author:zhangxingxing 0027012120
 * @date:2019/3/15
 * @time:17:39
 *//*

@Configuration
@Aspect
@Order(20)
public class PageHelperAop {

    private static final Logger logger = LoggerFactory.getLogger(PageHelperAop.class);

    */
/**
     * 切点为所有controller包下方法
     *//*

    @Pointcut("@annotation(com.iwhalecloud.mgtcenter.common.annotation.PagingAnnotation)")
    public void PageHelperPoint() {

    }

    */
/**
     * 在service方法前执行,初始化分页参数
     *
     * @param joinPoint
     * @throws Throwable
     *//*

    @Before("PageHelperPoint()")
    public void doBefore(JoinPoint joinPoint) throws Throwable {
        logger.info("{} doBefore分页", joinPoint.getSignature());
        Object[] params = joinPoint.getArgs();
        // 只处理继承了PageQuery类的分页
        PageQuery pageQuery = null;
        for (int i = 0; i < params.length; i++) {
            if (params[i] instanceof PageQuery) {
                pageQuery = (PageQuery) params[i];
                break;
            }
        }

        if (pageQuery == null) {
            logger.error("{} 分页未按要求继承PageQuery", joinPoint.getSignature());
        } else {

            */
/**
             * 部分接口可以临时关闭分页
             * 
             * @author Zhang Kangkang
             *//*

            if (!pageQuery.getOpenPage()) {
                return;
            }

            // TODO 分页的默认值已经写在pageQuery类中了,有其他处理逻辑在此处加
            PageHelper.startPage(pageQuery.getPageNum(), pageQuery.getPageSize());
        }
    }

}
*/
